//
//  TeacherDetailViewController.m
//  HTP
//
//  Created by admin on 15/11/3.
//  Copyright © 2015年 nit. All rights reserved.
//

#import "TeacherDetailViewController.h"

@interface TeacherDetailViewController ()
@property (nonatomic,retain) UIImageView *teacherImg;

@property (nonatomic,retain) UILabel     *nameLbl;
@property (nonatomic,retain) UILabel     *goodLbl;
@property (nonatomic,strong) UILabel     *signLbl;

@property (nonatomic,retain) UILabel     *ageLbl;
@property (nonatomic,retain) UILabel     *timeLbl;
@property (nonatomic,retain) UILabel     *countLbl;

@property (nonatomic,strong) UIScrollView *backScrollView;
@end

@implementation TeacherDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self _initView];
    // Do any additional setup after loading the view.
}

- (void)viewDidAppear:(BOOL)animated{
//    [self.backScrollView setContentSize:CGSizeMake(ScreenWidth, ScreenHeihgt)];
    [self setData];
}
-(void)viewWillAppear:(BOOL)animated{
    [self.view setBackgroundColor:RGBCOLOR(232, 229, 220, 1)];
    [self addCustomTitleWithTitle:@"教师详情"];
    [self addCustomBackWithAction:@selector(backToQM) normalImg:SYSTEMBACKIMAGE selectImg:SYSTEMBACKIMAGE withPadding:5];
//    [self addCustomBackWithAction:@selector(backToQM) normalImg:SYSTEMBACKIMAGE selectImg:SYSTEMBACKIMAGE];
}
//TODO:绘制UI
-(void)_initView{
    [self.view addSubview:self.backScrollView];
    [self.backScrollView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view);
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.bottom.equalTo(self.view).offset(-49);
    }];
    _teacherImg = [[UIImageView alloc] init];
    [_teacherImg setBackgroundColor:[UIColor redColor]];
    [self.backScrollView addSubview:_teacherImg];
    [_teacherImg makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(0);
        make.left.equalTo(10);
        make.width.equalTo(self.backScrollView).offset(-20);
        make.height.equalTo(self.backScrollView.width).multipliedBy(2.0/3.0);
    }];
    
    UIImageView *imageLine = [[UIImageView alloc] init];
    [imageLine setImage:[UIImage imageNamed:@"teacher_h"]];
    [imageLine setBackgroundColor:RGBCOLOR(177, 177, 177, 0.6)];
    [self.backScrollView addSubview:imageLine];
    [imageLine makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_teacherImg.bottom).offset(10);
        make.left.and.right.equalTo(self.view);
        make.height.equalTo(2);
    }];
    
    _nameLbl = [self getNormolLabel];
    _nameLbl.font = [UIFont fontWithName:@"Helvetica-BoldOblique" size:18];
    _nameLbl.textColor = [UIColor blackColor];
    [self.backScrollView addSubview:_nameLbl];
    [_nameLbl makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageLine.bottom).offset(20);
        make.left.equalTo(0);
        make.width.equalTo(imageLine);
    }];
    _goodLbl = [self getNormolLabel];
    [self.backScrollView addSubview:_goodLbl];
    [_goodLbl makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_nameLbl.bottom).offset(15);
        make.left.and.right.equalTo(self.backScrollView);
    }];

    _signLbl = [self getNormolLabel];
    [_signLbl setTextColor:[UIColor blackColor]];
    [self.backScrollView addSubview:_signLbl];
    [_signLbl makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_goodLbl.bottom).offset(10);
        make.left.and.right.equalTo(self.view);
    }];

    UIImageView *imageLine_1 = [[UIImageView alloc] init];
    [imageLine_1 setImage:[UIImage imageNamed:@"teacher_h"]];
    [imageLine_1 setBackgroundColor:RGBCOLOR(177, 177, 177, 0.9)];
    [self.backScrollView addSubview:imageLine_1];
    [imageLine_1 makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_signLbl.bottom).offset(10);
        //        make.width.equalTo(_teacherImg);
        make.left.and.right.equalTo(self.view);
        make.height.equalTo(2);
    }];
    
    _ageLbl = [self getNormolLabel];
    _ageLbl.textAlignment = _TEXT_ALIGN_LEFT;
    [self.backScrollView addSubview:_ageLbl];
    [_ageLbl makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(20);
        make.right.equalTo(self.backScrollView).offset(-20);
        make.top.equalTo(imageLine_1.bottom).offset(15);
    }];
    _timeLbl = [self getNormolLabel];
    _timeLbl.textAlignment = _TEXT_ALIGN_LEFT;
    [self.backScrollView addSubview:_timeLbl];
    [_timeLbl makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(_ageLbl);
        make.top.equalTo(_ageLbl.bottom).offset(10);
    }];
    _countLbl = [self getNormolLabel];
    _countLbl.textAlignment = _TEXT_ALIGN_LEFT;
    [self.backScrollView addSubview:_countLbl];
    [_countLbl makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(_ageLbl);
        make.top.equalTo(_timeLbl.bottom).offset(10);
    }];
    UIButton *contactBtn = [[UIButton alloc] init];
    [contactBtn setTitle:@"联系老师" forState:UIControlStateNormal];
    [contactBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [contactBtn.titleLabel setFont:[UIFont systemFontOfSize:23]];
    [self.view addSubview:contactBtn];
    [contactBtn makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.bottom.equalTo(self.view);
        make.height.equalTo(49);
        make.width.equalTo(self.backScrollView.width).multipliedBy(0.5).offset(-0.5);
    }];
    
    UIButton *applyBtn = [[UIButton alloc] init];
    [applyBtn setTitle:@"立即报名" forState:UIControlStateNormal];
    [applyBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [applyBtn.titleLabel setFont:[UIFont systemFontOfSize:23]];
    [self.view addSubview:applyBtn];
    [applyBtn makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view);
        make.bottom.equalTo(self.view);
        make.height.equalTo(49);
        make.width.equalTo(self.backScrollView.width).multipliedBy(0.5).offset(-0.5);
    }];
    
    UIImageView *line_s = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"teacher_s"]];
    [line_s setBackgroundColor:[UIColor blackColor]];
    [self.view addSubview:line_s];
    [line_s makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(contactBtn.right);
        make.bottom.equalTo(self.view).offset(-10);
        make.width.equalTo(1);
        make.height.equalTo(29);
    }];
}

//TODO:重写get方法
-(UIScrollView *)backScrollView{
    if (!_backScrollView) {
        _backScrollView = [[UIScrollView alloc] init];
        _backScrollView.backgroundColor = [UIColor whiteColor];
        _backScrollView.userInteractionEnabled = YES;
    }
    return _backScrollView;
}
//TODO:action
-(void)setData{
    _nameLbl.text = @"青苗家教";
//    _goodLbl.text = @"计算机科学";
    _signLbl.text = @"我是一名青苗家教的好老师我是一名青苗家";
    _ageLbl.text  = @"教龄: 15年";
    _timeLbl.text = @"授课时长: 748";
    _countLbl.text = @"学生数: 12";
    [self.view layoutIfNeeded];
    [self.backScrollView layoutIfNeeded];
    [self.backScrollView setContentSize:CGSizeMake(ScreenWidth, CGRectGetMaxY(_countLbl.frame)+10)];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
